from datetime import timedelta

import logging
from redis import StrictRedis


# 设置配置类
class Config(object):
    # 设置调试模式
    DEBUG = True
    SECRET_KEY = 'ASDQWEQWE'
    # 数据库配置
    SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://root:mysql@localhost:3306/info19'
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    # 当视图函数结束时  自动提交一次回话
    SQLALCHEMY_COMMIT_ON_TEARDOWN = True

    # redis配置信息
    REDIS_HOST = '127.0.0.1'
    REDIS_PORT = 6379

    # session配置信息  为登录状态保持做准备
    # 存储类型
    SESSION_TYPE = 'redis'
    SESSION_REDIS = StrictRedis(host=REDIS_HOST, port=REDIS_PORT)
    # 签名存储
    SESSION_USE_SIGNER = True
    # session有效期
    PERMANENT_SESSION_LIFETIME = timedelta(seconds=3600 * 24 * 2)


# app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:mysql@localhost:3306/info19'
# app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = Flase

    # 默认日志级别
    LEVELNAME = logging.DEBUG
# 开发模式配置信息
class DevelopConfig(Config):
    pass


# 生产（线上）模式配置信息
class ProductConfig(Config):
    DEBUG = False
    LEVELNAME = logging.ERROR

# 测试模式配置信息
class TestingConfig(Config):
    TESTING = True


# 提供配置类的统一访问入口
config_dict = {
    'develop': DevelopConfig,
    'product': ProductConfig,
    'testing': TestingConfig
}
